package service.impl;

import dao.IRoleDao;
import domain.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.IRoleService;

import java.util.List;

/**
 * @author Freedy
 * @date 2020/12/25 23:20
 */
@Service
@Transactional
public class IRoleServiceImpl implements IRoleService {
    @Autowired
    private IRoleDao roleDao;

    @Override
    public List<Role> findAll() throws Exception {
        return roleDao.findAll();
    }

    @Override
    public void save(Role role) throws Exception {
        roleDao.save(role);
    }

    @Override
    public Role findById(String id) throws Exception {
        return roleDao.findById(id);
    }

    @Override
    public void addPermissionByRoleId(Integer[] ids, int id) throws Exception {
        for (int permissionId : ids) {
            roleDao.addPermissionByRoleId(permissionId,id);
        }
    }

    @Override
    public void deleteRole(String RoleId) throws Exception {
        roleDao.deleteRoleFromUsersRole(RoleId);
        roleDao.deleteRoleFromRolePermission(RoleId);
        roleDao.deleteRole(RoleId);
    }


}
